package wili.exp.simple;

import java.util.Map;

import wili.c.Ca;
import wili.exp.simple.antlr.opExpParser.VarContext;

class Svar extends Sexp {


	public String toString() {
		return name;
	}

	public String toNumString(Map cont) {
		if (cont == null)
			return name;
		return "" + this.value(cont);
	}

	public Svar(Node node) {
		super(node);
		Ca.asert(node.tree instanceof VarContext, node);
		this.name = node.getContent();
	}

	public Svar(String dName) {
		super("");
		this.name = dName;
	}

	@Override
	public Boolean isTrue(Map cont) {
		return (Boolean) cont.get(name);
	}

	@SuppressWarnings("all")
	@Override
	public <T> T value(Map cont) {
		Object ret = cont.get(name);
		if (ret instanceof String) {
			try {
				return (T) (Number) Integer.parseInt(ret.toString());
			} catch (Exception e) {
				return (T) (Number) Double.parseDouble(ret.toString());
			}
		}
		return (T) ret;
	}
}